package com.longteng.diamond.controller;

import com.longteng.diamond.domain.ScheduleJob;
import com.longteng.diamond.dubboservice.DubboDemoService;
import com.longteng.diamond.service.QuartzService;
import org.quartz.JobDetail;
import org.quartz.Trigger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator
 * DATE : 2018/8/26
 * TIME : 2:23
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:taki@qq.com">Administrator</a>
 */
@RestController
public class QuartzController {
    @Autowired
    QuartzService quartzService;
//    @Autowired
//    DubboDemoService dubboDemoService;

    @RequestMapping("/addJob")
    public void addJob(Integer hh,Integer mm){
        ScheduleJob scheduleJob=new ScheduleJob();
        scheduleJob.setTestPlanId(1);
        scheduleJob.setTestPlanName("test");
        scheduleJob.setWeekTimeList("[7]");
        scheduleJob.setHhTime(hh);
        scheduleJob.setMmTime(mm);
        quartzService.addQuartzJob(scheduleJob);
    }

    @RequestMapping("/getJob")
    public JobDetail getJob(){
        ScheduleJob scheduleJob=new ScheduleJob();
        scheduleJob.setJobName("1test");
        scheduleJob.setTestPlanId(1);
        scheduleJob.setTestPlanName("test");
        scheduleJob.setWeekTimeList("[7]");
       return quartzService.getJobDetail(scheduleJob);
    }
    @RequestMapping("/getT")
    public Trigger getT(){
        ScheduleJob scheduleJob=new ScheduleJob();
        scheduleJob.setJobName("1test");
        scheduleJob.setTestPlanId(1);
        scheduleJob.setTestPlanName("test");
        scheduleJob.setWeekTimeList("[7]");
        return quartzService.getTrigger(scheduleJob);
    }
    @RequestMapping("/updateJob")
    public void updateJob(Integer hh,Integer mm){
        ScheduleJob scheduleJob=new ScheduleJob();
        scheduleJob.setJobName("1test");
        scheduleJob.setTestPlanId(1);
        scheduleJob.setTestPlanName("test");
        scheduleJob.setWeekTimeList("[7]");
        scheduleJob.setHhTime(hh);
        scheduleJob.setMmTime(mm);
        quartzService.modifyQuartzJob(scheduleJob);
    }

    @RequestMapping("/deleteJob")
    public void updateJob(Integer id){
        quartzService.deleteQuartzJobById(id);
    }

    @RequestMapping("/dubbo")
    public String dubbo(){
//        String s =dubboDemoService.sayHi("hi");
//        System.out.println("调用返回结果:"+s);
//        return s;
        return null;
    }
}
